function DebounceBy(fn, t) {
  const delay = t || 1000;
  let timer;
  return function (f, d) {
    // console.log(a,b);
    // const args = arguments;
    // console.log(arguments);
    if (timer) {
      // console.log(timer, 123);
      clearTimeout(timer);
    }
    let callNow = !timer;

    timer = setTimeout(() => {
      timer = null;
    }, delay);
    if (callNow) fn.call(this, f, d);
  };
}
export default {
  name: "mixinUntil",
  data() {
    return {
      // key: 'id',//
      // ids: []// 选中数组
      tableData: [],
      loading: false,
      pagination: {
        pageNum: 0,
        pageSize: 10,
        total: 0,
        pageSizes: [10, 20, 30, 40, 50],
      },
      starttimefn: {
        disabledDate: (time) => {
          // 禁用今天之前的日期选择
          return (
            time.getTime() < new Date().getTime() - 24 * 60 * 60 * 1000 * 30
          );
        },
      },
      endtimefn: {
        disabledDate: this.disabledDate,
      },
    };
  },
  created() {
    // console.log(14);
  },
  computed: {
    // showBatch: function () {
    //   return !!this.ids.length
    // }
    exportName() {
      // console.log(this.$route);
      // console.log(this.$route.matched.filter((item) => item.name));
      return this.$route.name;
    },
  },
  methods: {
    getNumber(key) {
      // e.target.value = e.target.value.replace(/\D/g, "");
      // this.form[key] = this.form[key].replace(/\D/g, "");
      this.form[key] = this.form[key];
    },
    // 获取列表数据
    async getlists(getListfn, data) {
      this.loading = true;
      const { pageNum, pageSize } = this.pagination;
      let params = {
        ...data,
        pageNum: pageNum - 1 > 0 ? pageNum - 1 : 0,
        pageSize,
      };
      try {
        const res = await getListfn(params);
        // console.log(res, 78);
        if (res.code == 200 || res.rescode == 200) {
          const { data } = res;
          this.pagination.total =
            data.total || data.totalCount || data.length || 0;
          this.tableData = data || data.rows || data.dataList || [];
          // 如果第二页第三页第四页...数据没有，重新查询第一页的数据
          if (this.tableData.length == 0 && pageNum != 0) {
            this.handlePageChange(0);
          }
          this.loading = false;
        } else {
          // this.pagination.total = 0;
          // this.tableData = [];
          this.loading = false;
          // this.$message.error(res.msg)
        }
      } catch (error) {
        console.log(error);
        this.loading = false;
      }
    },
    // 多选框选中数据
    handleUpClose() {
      this.dialogVisible2 = false;
    },
    closeUploadDialog() {
      this.dialogVisible2 = false;
    },
    // 改变页码
    handlePageChange(page) {
      this.pagination.pageNum = page;
      this.refresh();
    },
    // 改变页数
    handleSizeChange(size) {
      this.pagination.pageSize = size;
      this.pagination.pageNum = 1;
      this.refresh();
    },
    disabledDate(time) {
      // 当时间小于A时间  就是不可选
      // console.log(this.form.startTime);
      return time.getTime() < new Date(this.form.startTime).getTime();
      // 上方的new Date(this.Atime).getTime()  是将日期格式'2022-02-10' 转成时间戳 1589068800000
    },
    handleExport() {
      let exportTip = "此操作将导出数据, 是否继续?";
      if (this.pagination.total > 20000) {
        exportTip = "日志数据量超过2万条，此操作将导出2万条数据, 是否继续?";
        // this.$message.error('日志数据量超过20000条，请重新筛选条件导出！');
      }
      this.$confirm(exportTip, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.export();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消导出",
          });
        });
    },
    async handleDelete(row) {
      this.$confirm("此操作将删除数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        closeOnClickModal: false,
      })
        .then(async () => {
          await this.delete(row);
          this.refresh();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
